package com.dq.demos.web.controller;

import com.dq.demos.web.pojo.ReqParamVO;
import com.dq.demos.web.pojo.ThirdUserBo;
import com.dq.demos.web.service.IYFKService;
import com.dq.demos.web.service.IZLBToYFKService;
import com.dq.demos.web.utils.BIPUtil;
import com.dq.demos.web.utils.ZLBInvoiceOFDUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.slf4j.Logger;
/**
 * 弃用
 *
 * @Author: wxf
 * @Description: TODO ???????????????????
 * @Date: 2025/4/21 16:34
 * @Version: 1.0
 *
 */
@RestController
@RequestMapping("/bxdToYFK_Delete")
public class BXZToFKController {
    private static Logger logger = LoggerFactory.getLogger(FPToYonFKController.class);
    @Autowired
    private IYFKService yfkService;
    @Autowired
    private ThirdUserBo thirdUserBo;

    /**
     * 付款单传友费控报销单保存接口
     * @param map  ??????? zlbUrl???????url??requestParam?????????body
     * @return
     * @throws Exception
     */
    @RequestMapping("/saveBxd")
    public String saveBxd(@RequestBody Map<String,String> map) throws  Exception{
        logger.info("----begin----> 调用友费控报销单保存开始");
        String url = map.get("zlbUrl").toString();
        String requestParam = map.get("requestParam").toString();
        logger.info("----> 付款单参数：【" + requestParam+"】");
        try{

            String toKenURL = thirdUserBo.getBaseURL()+thirdUserBo.getSuffixTokenURL();
            String token = yfkService.getToken(toKenURL, thirdUserBo.getAppKey(), thirdUserBo.getAppSecret());
            logger.info("---->获取费控token; accessToken = " + token) ;
            HashMap<String, String> acctokenmap = new HashMap<>();
            acctokenmap.put("access_token", token);

            String res = BIPUtil.getPostQueryParamAndBodyParam(url, acctokenmap, requestParam);
            JSONObject resp = JSONObject.parseObject(res);

            if("200".equals(resp.getString("code"))){
                logger.info("---->报销单保存接口响应: " + res);
            }else{
                throw new Exception("---->报销单保存友费控异常:报销单"+requestParam+"异常信息 " + resp);
            }
            Thread.sleep(1000);
            logger.info("---->报销单保存成功");
        }catch (Exception e){
            logger.error("--->费控报销单保存异常：异常信息【"+e.getMessage()+"】");
        }
        logger.info("----end----> 调用友费控报销单保存结束");
        return "调用报销单保存流程结束，是否异常请查看跳板系统日志!日志路径【C:\\yonyou\\log】";
    }

}
